package com.meet.controller;

import com.meet.bizservice.SettingsService;
import com.meet.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.Min;

@RestController
@RequestMapping("/settings")
@CrossOrigin
@Validated
public class MeetSettingsController {

    @Autowired
    private SettingsService settingsService;

    @GetMapping("/notifications")
    public Result<?> getNotificationSettings() {
        return settingsService.getNotificationSettings();
    }

    @PutMapping("/notifications")
    public Result<?> updateNotificationSettings(@RequestBody @Validated NotificationSettingsUpdateRequest request) {
        return settingsService.updateNotificationSettings(
                request.getMessageNotification(), request.getActivityReminder(),
                request.getActivityRecommendation(), request.getSystemNotification(),
                request.getNotificationStartHour(), request.getNotificationEndHour());
    }

    // Request DTO
    public static class NotificationSettingsUpdateRequest {
        private Boolean messageNotification;
        private Boolean activityReminder;
        private Boolean activityRecommendation;
        private Boolean systemNotification;
        @Min(value = 0, message = "开始时间小时必须大于等于0")
        private Integer notificationStartHour;
        @Min(value = 0, message = "结束时间小时必须大于等于0")
        private Integer notificationEndHour;

        // Getters and Setters
        public Boolean getMessageNotification() {
            return messageNotification;
        }

        public void setMessageNotification(Boolean messageNotification) {
            this.messageNotification = messageNotification;
        }

        public Boolean getActivityReminder() {
            return activityReminder;
        }

        public void setActivityReminder(Boolean activityReminder) {
            this.activityReminder = activityReminder;
        }

        public Boolean getActivityRecommendation() {
            return activityRecommendation;
        }

        public void setActivityRecommendation(Boolean activityRecommendation) {
            this.activityRecommendation = activityRecommendation;
        }

        public Boolean getSystemNotification() {
            return systemNotification;
        }

        public void setSystemNotification(Boolean systemNotification) {
            this.systemNotification = systemNotification;
        }

        public Integer getNotificationStartHour() {
            return notificationStartHour;
        }

        public void setNotificationStartHour(Integer notificationStartHour) {
            this.notificationStartHour = notificationStartHour;
        }

        public Integer getNotificationEndHour() {
            return notificationEndHour;
        }

        public void setNotificationEndHour(Integer notificationEndHour) {
            this.notificationEndHour = notificationEndHour;
        }
    }
}
